<template>
  <div style="text-align: left">
    <el-button class="add-button" type="primary" icon="el-icon-circle-plus-outline" @click="dialogFormVisible = true" style="margin: 18px">添加供应商</el-button>
    <el-dialog
      title="添加供应商"
      :visible.sync="dialogFormVisible"
      @close="clear"
      width="25%">
      <el-form :model="roleForm" :rules="rules" label-position="left"
               label-width="0px" v-loading="loading">
        <el-form-item prop="name">
          <el-input type="text" v-model="roleForm.name"
                    auto-complete="off" placeholder="供应商名"></el-input>
        </el-form-item>
        <el-form-item prop="content">
          <el-input type="text" v-model="roleForm.content"
                    auto-complete="off" placeholder="供应商描述"></el-input>
        </el-form-item>
        <el-form-item prop="content">
          <el-input type="text" v-model="roleForm.phone"
                    auto-complete="off" placeholder="联系方式"></el-input>
        </el-form-item>
        <el-form-item style="width: 100%">
          <el-button type="primary" style="width: 40%;background: #505458;border: none" v-on:click="createRole">添加</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
  export default {
    name: 'RoleAdd',
    data () {
      return {
        dialogFormVisible: false,
        rules: {
          name: [{required: true, message: '供应商名不能为空', trigger: 'blur'}],
          phone: [{required: true, message: '联系方式不能为空', trigger: 'blur'}]
        },
        checked: true,
        roleForm: {
          name: '',
          content: '',
          phone: ''
        },
        loading: false
      }
    },
    methods: {
      clear () {
        this.roleForm = {
          name: '',
          content: '',
          phone: ''
        }
      },
      createRole () {
        this.$axios
          .post('/Supplier', {
            name: this.roleForm.name,
            content: this.roleForm.content,
            phone: this.roleForm.phone
          })
          .then(resp => {
              this.$alert("新增成功", '提示', {
                confirmButtonText: '确定'
              })
              this.clear()
              this.$emit('onSubmit')
          })
          .catch(failResponse => {})
        this.dialogFormVisible = false
      }
    }
  }
</script>

<style scoped>

</style>
